using System;
using System.Collections;
using Holoville.HOTween;
using Holoville.HOTween.Core;
using Holoville.HOTween.Plugins;
using UnityEngine;

public class PuddingAnimation : MonoBehaviour
{
	private void Awake()
	{
		this.transformCache = base.transform;
		this.originalScale = this.transformCache.localScale;
	}

	private void OnEnable()
	{
		PuddingAnimation.Do(base.gameObject);
	}

	private void OnDisable()
	{
		this.Reset();
	}

	public IEnumerator coAnimate()
	{
		HOTween.Kill(this.transformCache);
		TweenParms parmsX = new TweenParms().Prop("localScale", new PlugVector3X(this.targetScale.x, this.ease, false));
		if (!this.playOnce)
		{
			parmsX.Loops(-1, LoopType.Yoyo);
		}
		HOTween.To(this.transformCache, this.duration * 0.5f, parmsX);
		yield return new WaitForSeconds(this.yDelay);
		TweenParms parmsY = new TweenParms().Prop("localScale", new PlugVector3Y(this.targetScale.y, this.ease, false));
		if (!this.playOnce)
		{
			parmsY.Loops(-1, LoopType.Yoyo);
		}
		else
		{
			parmsY.OnComplete(new TweenDelegate.TweenCallback(this.TweenScaleToOriginal));
		}
		HOTween.To(this.transformCache, this.duration * 0.5f, parmsY);
		yield break;
	}

	public static void Do(GameObject target)
	{
		PuddingAnimation puddingAnimation = target.GetComponent<PuddingAnimation>();
		if (puddingAnimation == null)
		{
			puddingAnimation = target.AddComponent<PuddingAnimation>();
		}
		puddingAnimation.StartCoroutine(puddingAnimation.coAnimate());
	}

	private void TweenScaleToOriginal()
	{
		HOTween.To(this.transformCache, this.duration * 0.5f, "localScale", this.originalScale);
	}

	private void Reset()
	{
		HOTween.Kill(this.transformCache);
		this.transformCache.localScale = this.originalScale;
	}

	public Vector2 targetScale = new Vector2(1.02f, 0.97f);

	public float duration = 1.2f;

	public bool playOnce;

	private float yDelay = 0.1f;

	private Transform transformCache;

	private Vector3 originalScale;

	private EaseType ease = EaseType.EaseInOutCubic;
}
